/*
 * @Author: your name
 * @Date: 2022-02-23 18:23:24
 * @LastEditTime: 2022-02-25 15:02:43
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /aone_flutter/lib/packages/e01/views/home/home_page.dart
 */
import 'package:aone_common/api/webui.dart';
import 'package:aone_common/router/routes.dart';
import 'package:aone_common/services/global_service.dart';
import 'package:aone_common/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:app01/env.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final services = Get.find<GlobalService>();
    final env = Env();

    return Scaffold(
      appBar: AppBar(
        title: Text('home.title'.tr),
        automaticallyImplyLeading: false,
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            const Text("DEMO用例"),
            Text(Env().envConfig.appTitle),
            OutlinedButton(
              onPressed: services.toggleTheme,
              child: const Text("切换主题"),
            ),
            OutlinedButton(
              onPressed: () => {Get.updateLocale(const Locale('en', 'US'))},
              child: const Text("切换英语"),
            ),
            OutlinedButton(
              onPressed: () => {Get.updateLocale(const Locale('zh', 'CN'))},
              child: const Text("切换中文"),
            ),
            OutlinedButton(
              onPressed: () => {},
              child: const Text("Input封装"),
            ),
            OutlinedButton(
              onPressed: () => {},
              child: const Text("Button封装"),
            ),
            OutlinedButton(
              onPressed: () async {
                final res = await WebUiApi.home();
                print(res);
              },
              child: const Text("HTTP请求"),
            ),
            OutlinedButton(
              onPressed: () {
                Fluttertoast.showToast(
                  msg: 'Toast',
                  backgroundColor: stringToColor('282828', 0.9),
                );
              },
              child: const Text("Toast"),
            ),
            OutlinedButton(
              onPressed: () {
                Get.toNamed(Routes.login);
              },
              child: const Text("To login"),
            ),
            OutlinedButton(
              onPressed: () {
                print(csrfTokenGenerator('https://pre-qt.a1pre04.com/', 'wilson999'));
              },
              child: const Text("csrf generate"),
            ),
            Text(env.envConfig.appDomain),
          ],
        ),
      ),
    );
  }
}
